package com.ktgj.customer.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.ktgj.common.core.annotation.Excel;
import com.ktgj.customer.domain.Customer;
import com.ktgj.customer.domain.vo.CommonFeedbackVo;
import com.ktgj.customer.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.CommonFeedbackMapper;
import com.ktgj.customer.domain.CommonFeedback;
import com.ktgj.customer.service.ICommonFeedbackService;

/**
 * 意见反馈Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-22
 */
@Service
public class CommonFeedbackServiceImpl implements ICommonFeedbackService 
{
    @Autowired
    private CommonFeedbackMapper commonFeedbackMapper;
    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 查询意见反馈
     * 
     * @param feedbackId 意见反馈ID
     * @return 意见反馈
     */
    @Override
    public CommonFeedback selectCommonFeedbackById(Long feedbackId)
    {
        return commonFeedbackMapper.selectCommonFeedbackById(feedbackId);
    }

    /**
     * 查询意见反馈列表
     * 
     * @param commonFeedback 意见反馈
     * @return 意见反馈
     */
    @Override
    public List<CommonFeedback> selectCommonFeedbackList(CommonFeedback commonFeedback)
    {
        return commonFeedbackMapper.selectCommonFeedbackList(commonFeedback);
    }

    /**
     * 新增意见反馈
     * 
     * @param commonFeedback 意见反馈
     * @return 结果
     */
    @Override
    public int insertCommonFeedback(CommonFeedback commonFeedback)
    {
        return commonFeedbackMapper.insertCommonFeedback(commonFeedback);
    }

    /**
     * 修改意见反馈
     * 
     * @param commonFeedback 意见反馈
     * @return 结果
     */
    @Override
    public int updateCommonFeedback(CommonFeedback commonFeedback)
    {
        return commonFeedbackMapper.updateCommonFeedback(commonFeedback);
    }

    /**
     * 批量删除意见反馈
     * 
     * @param feedbackIds 需要删除的意见反馈ID
     * @return 结果
     */
    @Override
    public int deleteCommonFeedbackByIds(Long[] feedbackIds)
    {
        return commonFeedbackMapper.deleteCommonFeedbackByIds(feedbackIds);
    }

    /**
     * 删除意见反馈信息
     * 
     * @param feedbackId 意见反馈ID
     * @return 结果
     */
    @Override
    public int deleteCommonFeedbackById(Long feedbackId)
    {
        return commonFeedbackMapper.deleteCommonFeedbackById(feedbackId);
    }

    /**
     * 写新反馈
     * */
    @Override
    public int insertCommonFeedbackByFeedbackId(Long customerId, String feedbackContent, String phoneNumber) {
        CommonFeedback commonFeedback = new CommonFeedback();
        commonFeedback.setCustomerId(customerId);
        commonFeedback.setFeedbackContent(feedbackContent);
        commonFeedback.setPhoneNumber(phoneNumber);
        commonFeedback.setFeedbackTime(new Date());
        return commonFeedbackMapper.insertCommonFeedbackByFeedbackId(commonFeedback);
    }

    /**
     * 查看历史
     * */
    @Override
    public List<CommonFeedbackVo> selectCommonFeedbackByCustomerId(Long customerId) {
        List<CommonFeedback> commonFeedbackList = commonFeedbackMapper.selectCommonFeedbackByCustomerId(customerId);
        List<CommonFeedbackVo> commonFeedbackVoList = new CopyOnWriteArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (CommonFeedback commonFeedback : commonFeedbackList) {
            CommonFeedbackVo commonFeedbackVo = new CommonFeedbackVo();
            commonFeedbackVo.setFeedbackContent(commonFeedback.getFeedbackContent());
            commonFeedbackVo.setFeedbackTime(format.format(commonFeedback.getFeedbackTime()));
            commonFeedbackVo.setReplyContent(commonFeedback.getFeedback());
            commonFeedbackVoList.add(commonFeedbackVo);
        }
        return commonFeedbackVoList;
    }
}
